AddCSLuaFile('turret.lua')

registerFunction("turretFire", "e:nnnnn", "", function(self, args)
	//Point,Damage,force,spread,number
	local op1, op2, op3, op4, op5,op6 = args[2], args[3], args[4], args[5], args[6], args[7]
    	local rv1, rv2, rv3,rv4,rv5,rv6 = op1[1](self,op1), op2[1](self,op2), op3[1](self,op3), op4[1](self,op4),op5[1](self,op5),op6[1](self,op6)
	if(!validEntity(rv1)) then return end
	if(!isOwner(self, rv1)) then return end
	shootOrigin = rv1:GetPos()
	shootAngles = rv1:GetAngles()
	if (rv2 == 2) then
		shootDir = shootAngles:Right()
	elseif (rv2 == 3) then
		shootDir = shootAngles:Forward()
	else
		shootDir = shootAngles:Up()
	end
	//if (rv1:isPlayer()) then
		//shootOrigin = shootOrigin + Vector(0,0,60)
	//end
	//self.entity:EmitSound( Sound("Weapon_smg1.Single") )
	local bullet = {}
		bullet.Num 		= rv6
		bullet.Src 			= shootOrigin
		bullet.Dir 			= shootDir
		bullet.Spread 		= rv5
		bullet.Tracer		= 1
		bullet.Force		= rv4
		bullet.Damage		= rv3
		bullet.Attacker 	= self.player
	rv1:FireBullets( bullet )
	
	// Make a muzzle flash
	local effectdata = EffectData()
		effectdata:SetOrigin( shootOrigin )
		effectdata:SetAngle( rv1:GetAngles():Up() )
		effectdata:SetScale( 1 )
	util.Effect( "MuzzleEffect", effectdata )

	
end)

registerFunction("freeze", "e:n", "", function(self,args)
	local op1, op2 = args[2], args[3]
	local rv1= op1[1](self,op1)
	local rv2= op2[1](self,op2)
	if(!validEntity(rv1)) then return end
	if(!isOwner(self, rv1)) then return end
	if (rv2 ==1) then
		rv1:GetPhysicsObject():EnableMotion( false )
	else
		rv1:GetPhysicsObject():EnableMotion( true )
		rv1:GetPhysicsObject():Wake()
	end
end)


	









